﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;

namespace CheckProxy
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCheck_Click(object sender, EventArgs e)
        {
            int port = Convert.ToInt32(this.txtPort.Text);
            if (SoketConnect(this.txtIP.Text, port))
            {
                this.lblStatus.Text = "Live............";
            }
            else
            {
                this.lblStatus.Text = "Die............";
            }
        }

        public static bool SoketConnect(string host, int port)
        {
            bool flag = false;
            try
            {
                Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 200);
                IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(host), port);
                socket.Connect(remoteEP);
                if (socket.Connected)
                {
                    flag = true;
                }
                socket.Close();
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }
    }
}
